package com.ruoyi.wms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wms.domain.WmsOutboundOrder;
import com.ruoyi.wms.service.IWmsOutboundOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiImplicitParam;

/**
 * 出库单Controller
 * 
 * @author ruoyi
 * @date 2024-01-01
 */
@Api(tags = "出库单管理")
@RestController
@RequestMapping("/wms/outbound/order")
public class WmsOutboundOrderController extends BaseController
{
    @Autowired
    private IWmsOutboundOrderService wmsOutboundOrderService;

    /**
     * 查询出库单列表
     */
    @ApiOperation("查询出库单列表")
    @PreAuthorize("@ss.hasPermi('wms:outbound:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(WmsOutboundOrder wmsOutboundOrder)
    {
        startPage();
        List<WmsOutboundOrder> list = wmsOutboundOrderService.selectWmsOutboundOrderList(wmsOutboundOrder);
        return getDataTable(list);
    }

    /**
     * 导出出库单列表
     */
    @ApiOperation("导出出库单列表")
    @PreAuthorize("@ss.hasPermi('wms:outbound:order:export')")
    @Log(title = "出库单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsOutboundOrder wmsOutboundOrder)
    {
        List<WmsOutboundOrder> list = wmsOutboundOrderService.selectWmsOutboundOrderList(wmsOutboundOrder);
        ExcelUtil<WmsOutboundOrder> util = new ExcelUtil<WmsOutboundOrder>(WmsOutboundOrder.class);
        util.exportExcel(response, list, "出库单数据");
    }

    /**
     * 获取出库单详细信息
     */
    @ApiOperation("获取出库单详细信息")
    @ApiImplicitParam(name = "orderId", value = "出库单ID", required = true, dataType = "Long", paramType = "path")
    @PreAuthorize("@ss.hasPermi('wms:outbound:order:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return success(wmsOutboundOrderService.selectWmsOutboundOrderById(orderId));
    }

    /**
     * 新增出库单
     */
    @ApiOperation("新增出库单")
    @PreAuthorize("@ss.hasPermi('wms:outbound:order:add')")
    @Log(title = "出库单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsOutboundOrder wmsOutboundOrder)
    {
        return toAjax(wmsOutboundOrderService.insertWmsOutboundOrder(wmsOutboundOrder));
    }

    /**
     * 修改出库单
     */
    @ApiOperation("修改出库单")
    @PreAuthorize("@ss.hasPermi('wms:outbound:order:edit')")
    @Log(title = "出库单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsOutboundOrder wmsOutboundOrder)
    {
        return toAjax(wmsOutboundOrderService.updateWmsOutboundOrder(wmsOutboundOrder));
    }

    /**
     * 删除出库单
     */
    @ApiOperation("删除出库单")
    @ApiImplicitParam(name = "orderIds", value = "出库单ID数组", required = true, dataType = "Long[]", paramType = "path")
    @PreAuthorize("@ss.hasPermi('wms:outbound:order:remove')")
    @Log(title = "出库单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(wmsOutboundOrderService.deleteWmsOutboundOrderByIds(orderIds));
    }

    /**
     * 库存分配
     */
    @ApiOperation("库存分配")
    @ApiImplicitParam(name = "orderId", value = "出库单ID", required = true, dataType = "Long", paramType = "path")
    @PreAuthorize("@ss.hasPermi('wms:outbound:order:allocate')")
    @Log(title = "出库单", businessType = BusinessType.UPDATE)
    @PutMapping("/allocate/{orderId}")
    public AjaxResult allocateInventory(@PathVariable("orderId") Long orderId)
    {
        return toAjax(wmsOutboundOrderService.allocateInventory(orderId));
    }

    /**
     * 开始拣货
     */
    @ApiOperation("开始拣货")
    @ApiImplicitParam(name = "orderId", value = "出库单ID", required = true, dataType = "Long", paramType = "path")
    @PreAuthorize("@ss.hasPermi('wms:outbound:order:pick')")
    @Log(title = "出库单", businessType = BusinessType.UPDATE)
    @PutMapping("/startPicking/{orderId}")
    public AjaxResult startPicking(@PathVariable("orderId") Long orderId)
    {
        return toAjax(wmsOutboundOrderService.startPicking(orderId));
    }

    /**
     * 确认拣货
     */
    @ApiOperation("确认拣货")
    @ApiImplicitParam(name = "orderId", value = "出库单ID", required = true, dataType = "Long", paramType = "path")
    @PreAuthorize("@ss.hasPermi('wms:outbound:order:pick')")
    @Log(title = "出库单", businessType = BusinessType.UPDATE)
    @PutMapping("/pick/{orderId}")
    public AjaxResult confirmPicking(@PathVariable("orderId") Long orderId)
    {
        return toAjax(wmsOutboundOrderService.confirmPicking(orderId));
    }

    /**
     * 确认出库
     */
    @ApiOperation("确认出库")
    @ApiImplicitParam(name = "orderId", value = "出库单ID", required = true, dataType = "Long", paramType = "path")
    @PreAuthorize("@ss.hasPermi('wms:outbound:order:confirm')")
    @Log(title = "出库单", businessType = BusinessType.UPDATE)
    @PutMapping("/confirm/{orderId}")
    public AjaxResult confirmOutbound(@PathVariable("orderId") Long orderId)
    {
        return toAjax(wmsOutboundOrderService.confirmOutbound(orderId));
    }

    /**
     * 取消出库单
     */
    @ApiOperation("取消出库单")
    @ApiImplicitParam(name = "orderId", value = "出库单ID", required = true, dataType = "Long", paramType = "path")
    @PreAuthorize("@ss.hasPermi('wms:outbound:order:cancel')")
    @Log(title = "出库单", businessType = BusinessType.UPDATE)
    @PutMapping("/cancel/{orderId}")
    public AjaxResult cancelOutboundOrder(@PathVariable("orderId") Long orderId)
    {
        return toAjax(wmsOutboundOrderService.cancelOutboundOrder(orderId));
    }

    /**
     * 根据出库单号查询出库单
     */
    @ApiOperation("根据出库单号查询出库单")
    @ApiImplicitParam(name = "orderNo", value = "出库单号", required = true, dataType = "String", paramType = "path")
    @PreAuthorize("@ss.hasPermi('wms:outbound:order:query')")
    @GetMapping("/orderNo/{orderNo}")
    public AjaxResult getInfoByOrderNo(@PathVariable("orderNo") String orderNo)
    {
        return success(wmsOutboundOrderService.selectWmsOutboundOrderByOrderNo(orderNo, null));
    }


}